<?php

require_once dirname(__FILE__) . '/../classes/Bootstrap.php';

try {
	// Get front controller instance
	$front = Zend_Controller_Front::getInstance();
	// Set modular structure directories
	$front->addModuleDirectory(BASE_DIR . '/application/modules');
	
	// Set front controller router
	$router = new Zend_Controller_Router_Rewrite();
	
	$dispatcher = $front->getDispatcher();
	$request = $front->getRequest();
	
	$route = new Route(array(), $dispatcher, $request);
	
	$router->addRoute('default', $route);

	$front->setRouter($router);
	
	// Register controller plugins
	$front->registerPlugin(new Controller_Plugin_DefaultCharset());
	$front->registerPlugin(new Controller_Plugin_FormParser());
	//$front->registerPlugin(new Controller_Plugin_Log());

	// Init View Renderer
	$view = new View();
	$tplFormat = 'phtml';
	
	$renderer = new Zend_Controller_Action_Helper_ViewRenderer();
	$renderer->setView($view);
	$renderer->setViewSuffix($tplFormat);
	// Set view renderer helper
	Zend_Controller_Action_HelperBroker::addHelper($renderer);

	// Init Zend_Layout
	$layout = Zend_Layout::startMvc();
	$layout->setViewSuffix($tplFormat);

	// Switch off error handler plugin
	$front->setParam('noErrorHandler', true);
	// Throw exceptions in dispatch loop
	$front->throwExceptions(true);

	// Set return response flag
	$front->returnResponse(true);
	
	// Create request object
	$request = new Request();
	
	// Dispatch request
	$response = $front->dispatch($request);
	// Output response
	$response->sendResponse();
} catch (Exception $e) {
	// Show exception
	require 'ErrorLowlevel.php';
}
